<template>
	<view class="content">
    
		<button @click="login" class="btu">淘宝授权登录</button>
		<button @click="logout" class="btu">退出淘宝登录</button>
		
		<button @click="detail" class="btu">打开商品详情</button>
		<button @click="shop" class="btu">打开店铺</button>
		<button @click="url" class="btu">URL打开page</button>
		
		
		<button @click="OpenMyCart" class="btu">打开我的购物车</button>
		<button @click="OpenMyOrders" class="btu">打开我的订单</button>
		
		<button @click="checkSession" class="btu">判断用户Session有效性</button>
		<button @click="getSession" class="btu">获取用户Session信息</button>
	</view>
</template>

<script>
// require插件名称  
const taobaologin= uni.requireNativePlugin('dasu-baichuan_android'); 
// require插件名称 
	export default {
		data() {
			return {
			}
		},
		onLoad() {

		},
		methods: {
           login(){
				taobaologin.login(result=>{
					
					uni.showToast({title:JSON.stringify(result),icon:'none'}); 
						
					  if(result.type=="success")
					  {
						    //授权成功 
					  }else{
						  //授权失败，包括用户取消登录	 
					  }
					
					
				});
			  
		   },logout(){
			   
			 	taobaologin.logout(result=>{
			 		
			 		uni.showToast({title:JSON.stringify(result),icon:'none'});
					
					 if(result.type=="success")
					 {
					  //退出成功 
					 }else{
						 //退出失败
					console.log("code:"+result.code+" - "+"msg:"+result.msg);	 
					 }	
			 	});   
			   
		   },detail()  //商品详情页面
		   {
			   taobaologin.detailPage({itemId:"587811576939"},result=>{
			   	 if(result.type=="success")
			   	 {
			   	  //成功 
			   	 }else{
			   		 //失败
			   	 console.log("code:"+result.code+" - "+"msg:"+result.msg);	 
			   	 }	
			   }); 
			   
		   },shop()//打开店铺
		   {
			    taobaologin.shopPage({shopId:"332454339"},result=>{
			   	 if(result.type=="success")
			   	 {
			   	  //成功 
			   	 }else{
			   		 //失败
			   	 console.log("code:"+result.code+" - "+"msg:"+result.msg);	 
			   	 }	
			   }); 
			   
		   },url()
		   {
			    taobaologin.url({url:"https://detail.tmall.com/item.htm?spm=a1z10.1-b-s.w5003-21423330589.2.4f2c1fd0ibczg0&id=587811576939&scene=taobao_shop"},result=>{
			   	 if(result.type=="success")
			   	 {
			   	  //成功 
			   	 }else{
			   		 //失败
			   	 console.log("code:"+result.code+" - "+"msg:"+result.msg);	 
			   	 }	
			   });
			   
		   },checkSession()
		   {
			   taobaologin.checkSession(result=>{
				   
				   uni.showToast({title:JSON.stringify(result),icon:'none'});
				   
			   });
			      
			   
		   }
		   ,getSession()
		   {
		   			   taobaologin.getSession(result=>{
		   				   
		   				   uni.showToast({title:JSON.stringify(result),icon:'none'});
		   				   
		   			   });	   
		   },
		   OpenMyCart()
		   {
			    //打开我的购物车
			    taobaologin.OpenMyCart(result=>{
			   				   
			   		uni.showToast({title:JSON.stringify(result),icon:'none'});
					
					   if(result.type=="success")
					   {
						   //操作成功，返回内容 result.msg
						 console.log("msg:"+result.msg);	 
					   }else{
						   
						  //失败
						 console.log("code:"+result.code+" - "+"msg:"+result.msg);	   
					   }
			   				   
			   }); 
				 
		   },
		   OpenMyOrders()
		   {
			     //打开我的订单
				// status   默认跳转页面(0:全部, 1:待付款, 2:待发货, 3:待收货, 4:待评价)
				// type    为 true 显示所有订单，为false只显示通过当前app下单的订单
			    taobaologin.OpenMyOrders({status:0,type:true},result=>{
			   				   
			   		uni.showToast({title:JSON.stringify(result),icon:'none'});
			   					
			   					   if(result.type=="success")
			   					   {
			   						   //操作成功，返回内容 result.msg
			   						 console.log("msg:"+result.msg);	 
			   					   }else{
			   						   
			   						  //失败
			   						 console.log("code:"+result.code+" - "+"msg:"+result.msg);	   
			   					   }
			   				   
			   }); 
			   
		   }
		   
		   
		}
	}
</script>

<style>
	.btu {
		margin-top:20px; margin-left: 10px; margin-right: 10px;
	}
 
</style>